package com.tsunami.auth.controller;

import com.tsunami.auth.service.admin.ITenantService;
import com.tsunami.authority.dto.admin.TenantSaveDTO;
import com.tsunami.authority.dto.admin.TenantUpdateDTO;
import com.tsunami.authority.entity.admin.Tenant;
import com.tsunami.base.R;
import com.tsunami.log.annotation.SysLog;
import com.tsunami.user.annotation.LoginUser;
import com.tsunami.user.model.SysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Classname TenantController
 * @Description TODO
 * @Date 2021-12-02 16:55
 * @Created by lx
 */
@RestController
@RequestMapping("/tenant")
@Api(value = "Tenant", tags = "租户管理")
public class TenantController {
    @Autowired
    private ITenantService tenantService;

    @GetMapping("page")
    @ApiOperation(notes = "租户列表（分页）",value = "获取租户列表")
    @SysLog("获取租户列表")
    public R list(Integer pageNum,
                  Integer pageSize,
                  String orderByColumn,
                  String isAsc,
                  Tenant data){
        return tenantService.selectPageList(data);
    }

    @ApiOperation(value = "新增租户", notes = "新增租户")
    @PostMapping("/save")
    @SysLog("新增租户")
    public R save(@LoginUser SysUser user, @Validated TenantSaveDTO data){
        tenantService.saveTenant(user,data);
        return R.ok();
    }
    @ApiOperation(value = "更新租户", notes = "更新租户")
    @PostMapping("/update")
    @SysLog("更新租户")
    public R update(@LoginUser SysUser user, @Validated TenantUpdateDTO data){
        tenantService.updateTenant(user,data);
        return R.ok();
    }

    @ApiOperation(value = "删除租户", notes = "根据id物理删除租户")
    @DeleteMapping("/delete")
    @SysLog("删除租户")
    public R delete(@RequestParam("ids[]") List<Long> ids) {
        tenantService.remove(ids);
        return R.ok();
    }
}
